<?php
/**
 * singleton.php
 * Created by PhpStorm.
 * User: 江小波
 * Date: 2018/09/08
 * Time: 10:59
 */
class SingleObject {
    // 创建 SingleObject 的一个对象
    protected static $instance = null;
    protected static $testIndex = 0;
    /**
     * 单例模式调用
     * @param $option
     * @return static
     */
    public static function getInstance($option=[]){
        var_dump(self::$instance);
        $class = get_called_class();
        if (isset(self::$instance[$class])){
            return self::$instance[$class];
        }
        self::$testIndex++;
        echo("Count : ".self::$testIndex."\n");
        self::$instance[$class] = new $class($option);
//        self::$instance[$class] = new self($option);
        return self::$instance[$class];
    }
}

SingleObject::getInstance();
SingleObject::getInstance();
SingleObject::getInstance();